const { mongoose } = require('../db');

const schema = mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        required: true,
        ref:'User',
        autopopulate: true,
    },
    page: {
        type: String,
        required: true,
    },
    url: {
        type: String,
        required: true,
    },
    filename: {
        type: String,
        required: true,
    },
    mimetype: {
        type: String,
        required: true,
    },
    size: Number,
    path: String,
    fieldname: String,
    encoding: String,
    destination: String,
    deletedAt: { type: Date, default: null },
}, {
    timestamps: true,
});

schema.plugin(require('mongoose-autopopulate'));

module.exports = mongoose.model('File', schema, 'file');